//
//  WBHomeViewController.swift
//  CSWeibo
//
//  Created by 白长松 on 16/6/29.
//  Copyright © 2016年 白长松. All rights reserved.
//

import UIKit

private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {

    //定义状态数据数组
    private lazy var statusList: [String] = [String]()
    
    override func loadData() {
        
        DispatchQueue.main.after(when: DispatchTime.now() + 1) {
            for i in 0..<15 {
                if self.isPullUp {
                    self.statusList.append(i.description)
                } else {
                    self.statusList.insert(i.description, at: 0)
                }
            }
            self.refreshControl?.endRefreshing()
            
            self.isPullUp = false
            
            self.tableView?.reloadData()
        }
        
    }
    
    //好友按钮监听方法
    @objc private func showFriends() -> () {
        
        let vc = WBDemoViewController()
        
        navigationController?.pushViewController(vc, animated: true)
    }
}

extension WBHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        
        return cell
    }
    
}


//MARK: - 设置界面
extension WBHomeViewController {
    
    //设置界面
    override func setupTableView() {
        super.setupTableView()
        
        //设置导航栏按钮
        navItem.leftBarButtonItem = UIBarButtonItem.init(title: "好友", target: self, action: #selector(showFriends))
        
        //注册原型cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
